﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace YFINGenerator
{
    partial class Program
    {
        static void Main(string[] args)
        {
            //foreach (var e in vmInfos)
            //{
            //    Console.WriteLine(Factory.VMHeaderGenerator(e));
            //    Console.ReadKey();
            //}
            //Models();
            //Services();
            VMs();
            Console.WriteLine("完成");
            Console.ReadKey();
        }

        static void Models()
        {
            Directory.CreateDirectory("D:/YFIN/Models");
            foreach (var e in EntityInfos)
            {
                var fs = new FileStream("D:/YFIN/Models/" + e.Name.Replace("YFIN_", "Model") + ".cs", FileMode.Create);
                var buf = Encoding.Default.GetBytes(Factory.ModelGenerator(e));
                fs.Write(buf, 0, buf.Length);
                fs.Close();
            }
        }

        static void Services()
        {
            Directory.CreateDirectory("D:/YFIN/Services/User");
            Directory.CreateDirectory("D:/YFIN/Services/Toolkit");
            Directory.CreateDirectory("D:/YFIN/Services/NewsAndCourse");
            Directory.CreateDirectory("D:/YFIN/Services/MarketTrend");
            Directory.CreateDirectory("D:/YFIN/Services/Lockbox");
            Directory.CreateDirectory("D:/YFIN/Services/Admin");
            foreach (var e in EntityInfos)
            {
                var fs = new FileStream("D:/YFIN/Services/" + e.Directory + "/" 
                    + e.Name.Replace("YFIN_", "") + "Service.svc.cs", FileMode.Create);
                var buf = Encoding.Default.GetBytes(Factory.ServiceGenerator(e));
                fs.Write(buf, 0, buf.Length);
                fs.Close();
            } 
            foreach (var e in EntityInfos)
            {
                var fs = new FileStream("D:/YFIN/Services/" + e.Directory + "/I"
                    + e.Name.Replace("YFIN_", "") + "Service.cs", FileMode.Create);
                var buf = Encoding.Default.GetBytes(Factory.IServiceGenerator(e));
                fs.Write(buf, 0, buf.Length);
                fs.Close();
            } 
            foreach (var e in EntityInfos)
            {
                var fs = new FileStream("D:/YFIN/Services/" + e.Directory + "/"
                    + e.Name.Replace("YFIN_", "") + "Service.svc", FileMode.Create);
                var buf = Encoding.Default.GetBytes(Factory.SvcGenerator(e));
                fs.Write(buf, 0, buf.Length);
                fs.Close();
            }
        }
        static void VMs()
        {
            Directory.CreateDirectory("D:/YFIN/VM/User");
            Directory.CreateDirectory("D:/YFIN/VM/Toolkit");
            Directory.CreateDirectory("D:/YFIN/VM/NewsAndCourse");
            Directory.CreateDirectory("D:/YFIN/VM/MarketTrend");
            Directory.CreateDirectory("D:/YFIN/VM/Lockbox");
            Directory.CreateDirectory("D:/YFIN/VM/Admin");
            foreach (var e in vmInfos)
            {
                var fs = new FileStream("D:/YFIN/VM/" + e.Group + "/"
                    + e.Name + ".cs", FileMode.Create);
                var buf = Encoding.Default.GetBytes(Factory.VMHeaderGenerator(e));
                fs.Write(buf, 0, buf.Length);
                fs.Close();
            } 
        }
    }
}
